import baiduDemo.BaiduDemo;
import dto.TecentDetectDto;
import exportExcel.DetectExcelBuilder;
import exportExcel.DetectExcelWorker;
import faceService.FaceDetect;
import org.apache.commons.collections.map.HashedMap;

import java.io.File;
import java.util.Map;

/**
 * Created by Administrator on 2017/10/11.
 */
public class export {
    public static void main(String[] args) throws Exception {
        FaceDetect faceDetect = new FaceDetect();
        BaiduDemo baiduDemo = new BaiduDemo();

        String filePath = "C:\\Users\\Administrator\\Desktop\\pic1";
        File root = new File(filePath);
        File[] files = root.listFiles();
        Map<String, Integer> tencetFaceCount = new HashedMap();
        Map<String, Integer> baiduFaceCount = new HashedMap();
        int i = 1;
        String savePath = "C:\\Users\\Administrator\\Desktop\\result.xlsx";

        for (File file : files) {
            if (!file.isDirectory()) {
                TecentDetectDto tecentDetectDto = faceDetect.faceDetect(file.getAbsolutePath());
                String name = file.getName().replace(".jpg", "");
                if (tecentDetectDto.getMessage().equals("OK")) {
                    tencetFaceCount.put(name, tecentDetectDto.getData().getFace().size());
                } else {
                    if (tecentDetectDto.getCode().equals("-1101")) {
                        tencetFaceCount.put(name, 0);
                    } else {
                        tencetFaceCount.put(name, -1);
                    }
                }
                int baiduCount = baiduDemo.detect(file.getAbsolutePath());
                baiduFaceCount.put(name, baiduCount);
            }
            System.out.print("Finished :" + i + "/" + files.length + "\n");
            i++;
        }

        try {
            DetectExcelWorker detectExcelWorker = new DetectExcelWorker();
            detectExcelWorker.buildSummaryAndData(tencetFaceCount, baiduFaceCount);

            DetectExcelBuilder detectExcelBuilder = new DetectExcelBuilder();
            detectExcelBuilder.drawExcel(savePath, detectExcelWorker);
            detectExcelWorker.cleanExportWorker();

        } catch (Exception e) {
            e.printStackTrace();
        }

        faceDetect.faceDetect("C:\\Users\\Administrator\\Desktop\\facePic1\\d.jpg");


    }
}
